<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">

      <el-form-item label="卖家真实姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入卖家真实姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卖家地址" prop="sellerAddress">
        <el-input
          v-model="queryParams.sellerAddress"
          placeholder="请输入卖家地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="入库时间">
        <el-date-picker
          v-model="queryParams.inboundDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="到期时间">
        <el-date-picker
          v-model="queryParams.expiryDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:seller:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['system:seller:edit']"-->
<!--        >修改</el-button>-->
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:seller:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:seller:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="sellerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="卖家真实姓名" align="center" prop="realName" />
      <el-table-column label="联系方式" align="center" prop="contact" />
      <el-table-column label="卖家地址" align="center" prop="sellerAddress" />
      <el-table-column label="订单编号" align="center" prop="orderNumber" />
      <el-table-column label="冷库名称" align="center" prop="coldName" />
      <el-table-column label="冷库地址" align="center" prop="coldAddress" />
      <el-table-column label="货物名称" align="center" prop="goodsName" />
      <el-table-column label="入库重量" align="center" prop="verifiedWeight" />
      <el-table-column label="入库数量" align="center" prop="actualQuantity" />
<!--      <el-table-column label="单位" align="center" prop="unitName" />-->
      <el-table-column label="入库时间" align="center" prop="inboundDate" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inboundDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="剩余重量" align="center" prop="remainingWeight" />
      <el-table-column label="剩余数量" align="center" prop="remainingQuantity" />
      <el-table-column label="到期时间" align="center" prop="expiryDate" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expiryDate) }}</span>
        </template>
      </el-table-column>


      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleOutInfo(scope.row)"
          >
<!--            v-hasPermi="['system:seller:edit']"-->
            出库详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改卖家对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="720px">
        <el-table v-loading="loading" :data="outOrderList" >
          <el-table-column label="出库订单编号" align="center" prop="stockOrderNumber" />
          <el-table-column label="出库数量" align="center" prop="outQuantity" />
          <el-table-column label="出库重量" align="center" prop="outWeight" />
          <el-table-column label="出库时间" align="center" prop="outTime" />
          <el-table-column label="质检人" align="center" prop="inspectionName" />
          <el-table-column label="质检时间" align="center" prop="inspectionTime" />
        </el-table>
    </el-dialog>

  </div>
</template>

<script>
import { listSeller, getSeller, delSeller, addSeller, updateSeller } from "@/api/seller/sellerInfo";

export default {
  name: "SellerInfo",
  dicts: ['sys_user_sex'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 卖家表格数据
      sellerList: [],
      // 卖家出库表格数据
      outOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        realName: null,
        sellerAddress:null,
        orderNumber:null,
        inboundDate:[],
        expiryDate:[]
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        account: [
          { required: true, message: "账号不能为空", trigger: "blur" }
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" }
        ],
        username: [
          { required: true, message: "用户名不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询卖家列表 */
    getList() {
      this.loading = true;
      console.log(this.queryParams);
      listSeller(this.queryParams).then(response => {
        console.log(response);
        this.sellerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },


    // 表单重置
    reset() {
      this.form = {
        id: null,
        account: null,
        realName: null,
        contact: null,
        address: null,
        goodsName: null,
        verifiedWeight: null,
        actualQuantity: null,
        unit: null,
        inboundDate: null,
        remainingWeight: null,
        remainingQuantity: null,
        expiryDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.inboundDate = [];
      this.queryParams.expiryDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.sellerId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加卖家";
    },
    /** 修改按钮操作 */
    handleOutInfo(row) {
      this.reset();
      const sellerInfoId = row.id || this.ids
      console.log("sellerInfoId",sellerInfoId)
      getSeller(sellerInfoId).then(response => {
        console.log("selleroutInfo",response);

        this.outOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.open = true;
        this.title = "卖家货物出库记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.sellerId != null) {
            updateSeller(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
          // else {
          //   addSeller(this.form).then(response => {
          //     this.$modal.msgSuccess("新增成功");
          //     this.open = false;
          //     this.getList();
          //   });
          // }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const sellerIds = row.sellerId || this.ids;
      this.$modal.confirm('是否确认删除卖家编号为"' + sellerIds + '"的数据项？').then(function() {
        return delSeller(sellerIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('seller/people/export', {
        ...this.queryParams
      }, `seller_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
